package com.prs.crm.service.cdxh.impl;

import java.text.DecimalFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

import com.prs.crm.dao.cdxh.MaterialTeamDao;
import com.prs.crm.domain.cdxh.EarningSal;
import com.prs.crm.domain.cdxh.HrPerson;
import com.prs.crm.domain.cdxh.MaterialProduct;
import com.prs.crm.domain.cdxh.SerialNumberss;
import com.prs.crm.domain.cdxh.material.MaterialPrint;
import com.prs.crm.domain.cdxh.material.MaterialPrintDetail;
import com.prs.crm.domain.cdxh.material.MaterialTeam;
import com.prs.crm.domain.cdxh.molding.Molding;
import com.prs.crm.domain.cdxh.production.ProvideRegime;
import com.prs.crm.domain.cdxh.wages.MaterialWages;
import com.prs.crm.service.cdxh.EarningSalService;
import com.prs.crm.service.cdxh.HrPersonService;
import com.prs.crm.service.cdxh.MaterialPrintService;
import com.prs.crm.service.cdxh.MaterialProductService;
import com.prs.crm.service.cdxh.MaterialTeamService;
import com.prs.crm.service.cdxh.MaterialWagesService;
import com.prs.crm.service.cdxh.MoldingService;
import com.prs.crm.service.cdxh.MoldingWagesService;
import com.prs.crm.service.cdxh.PrintWagesService;
import com.prs.crm.service.cdxh.ProvideRegimeService;
import com.prs.crm.service.cdxh.SerialNumberssService;
import com.prs.crm.service.impl.BaseServiceImpl;

/**
 * @author LanXiaoGang
 * @E-mail:lan9liang@163.com
 * @qq:7857553326
 * @version 创建时间：2010-12-6 上午10:41:01 简单说明
 */

public class MaterialTeamServiceImpl extends
		BaseServiceImpl<MaterialTeam, MaterialTeamDao> implements
		MaterialTeamService {
	private EarningSalService earningSalService;

	private SerialNumberssService serialNumberssService;

	private MaterialTeamService materialTeamService;

	private MaterialPrint materialPrint;

	private MaterialPrintService materialPrintService;

	private MaterialProduct materialProduct;

	private MaterialProductService materialProductService;

	private ProvideRegimeService provideRegimeService;

	private ProvideRegime provideRegime;

	private HrPerson hrPerson;

	private HrPersonService hrPersonService;

	private MoldingService moldingService;

	private MaterialWagesService materialWagesService;

	private MoldingWagesService moldingWagesService;

	private PrintWagesService printWagesService;

	@Override
	public void saveMaterialTeam(MaterialTeam materialTeam,
			String[] materialYanse, String[] materialNorm,
			String[] materialTanca, String[] materialPvc,
			String[] materialScal, String[] materialDop,
			String[] materialProductNum, String[] materialSjProNum,
			String[] materialSyWuLiao, String[] materialCustomer,
			String[] materialFeiLiao, String[] materialStopState,
			String[] materialSuDu, String[] materialRemark,
			String[] productNums, Integer[] idObject, String[] planOrOrderId,
			Date[] supplierDate, String[] rushOrder, String[] productCodes,
			String[] productPackstyle, Integer[] backProductSate) {
		int lengths = materialYanse.length;
		int inintNum = 0;
		double wages = 0.0;
		double funds = 0.0;
		int  insV=0;
		for (int i = 0; i < lengths; i++) {
			if (inintNum < lengths) {

				if (backProductSate[inintNum] == 4) {
					// 是打回生产
					 System.out.println("打回");
					MaterialProduct mOP = this.getMaterialProductService()
							.getMaterialProduct(idObject[i]);
					double materialProductNums = Double
							.parseDouble(materialProductNum[i]);
					double materialSjProNumss = Double
							.parseDouble(materialSjProNum[i]);
					if (materialSjProNumss >= materialProductNums) {
						double inerstV = mOP.getRemainderNum()
								+ materialSjProNumss;
						mOP.setRemainderNum(inerstV);
						mOP.setProductScal(materialScal[i]);
//						 mOP.setNeedNum(mOP.getNeedNum() - materialSjProNumss);
						mOP.setpLState(7);

					} else {
						double insertVV = mOP.getRemainderNum()
								+ materialSjProNumss;
						mOP.setRemainderNum(insertVV);
						mOP.setProductScal(materialScal[i]);
						mOP.setpLState(2);
						mOP.setNeedNum(mOP.getNeedNum() - materialSjProNumss);
					}
					this.getMaterialProductService().saveOrMaterialProduct(mOP);
					MaterialTeam MtObject = this.getMaterialTeamService()
							.getMaterialTeam(productCodes[i], planOrOrderId[i]);
					MtObject.setMaterialSyWuLiao((Double.parseDouble(MtObject
							.getMaterialSyWuLiao()) + materialSjProNumss) + "");
					this.getMaterialTeamService().saveOrMaterialTeam(MtObject);

					/**
					 * 打回订单工资单计算-----------------------start--------------------
					 * ---------------------
					 */
					if(insV==0){
						for(int x=0;x<lengths;x++){
							wages = wages + Double.parseDouble(materialSjProNum[x]);;
							funds = funds + Double.parseDouble(materialFeiLiao[x]);
						}
					/**
					 * 人员比对-----------------start-------
					 */
					// 每个人本次制定分到的实际数量
					double shiji_merNum = 0.0;
					// 每个人本次制定分到的 废料数量
					double feiliao_merNum = 0.0;
					String personNames = materialTeam.getMaterialProduction();
					String lengthss[] = personNames.split(",");
					int personlength = lengthss.length;
					DecimalFormat df = new DecimalFormat("##.000");
					if (personlength > 0) {
						// 大于一个人，需要平分
						shiji_merNum = Double.parseDouble(df.format(wages
								/ personlength));
						feiliao_merNum = Double.parseDouble(df.format(funds
								/ personlength));
					} else {
						// 一个人独享
						shiji_merNum = wages;
						feiliao_merNum = funds;
					}

					/**
					 * 人员比对------------------end------
					 */
					/**
					 * 工资单计算----------------------------------------------------
					 * --start wages funds
					 */
//					   System.out.println("shiji_merNum="+shiji_merNum);
//				        System.out.println("feiliao_merNum="+feiliao_merNum);
				
			
					
					ProvideRegime pdobjectA = this.getProvideRegimeService()
					.getProvideRegime("配料","实际产量",
							materialTeam.getMaterialClass(),
							materialTeam.getMaterialMachine());
			double shijichanliangNum = (double) pdobjectA.getSetNum();
			double jiangliDJ = pdobjectA.getRewardPrice();
			double chengfaDJ = pdobjectA.getPunishPrice();
			String uuDate=getCurrentDate();
			for (int z = 0; z < personlength; z++) {
				MaterialWages  mwObject=new MaterialWages();
				mwObject.setProStyles("实际产量");
				mwObject.setProvideNums(shijichanliangNum+"");
				mwObject.setProNames(lengthss[i]);
				mwObject.setPoundPrice(jiangliDJ);
				mwObject.setRwardPrice(chengfaDJ);
				mwObject.setRegDate(uuDate);
				mwObject.setThNums(shiji_merNum);
				mwObject.setDiscriminationValue(pdobjectA.getDiscriminationValue());
				this.getMaterialWagesService().save(mwObject);
				
			}


			ProvideRegime pdobjectB = this.getProvideRegimeService()
					.getProvideRegime("配料","废料",
							materialTeam.getMaterialClass(),
							materialTeam.getMaterialMachine());
			double feiliaoNum = (double) pdobjectB.getSetNum();
			double jiangliDJF = pdobjectB.getRewardPrice();
			double chengfaDJF = pdobjectB.getPunishPrice();
			
			for (int z = 0; z < personlength; z++) {
				MaterialWages  mwObject=new MaterialWages();
				mwObject.setProStyles("废料");
				mwObject.setProvideNums(feiliaoNum+"");
				mwObject.setProNames(lengthss[i]);
				mwObject.setPoundPrice(jiangliDJF);
				mwObject.setRwardPrice(chengfaDJF);
				mwObject.setRegDate(uuDate);
				mwObject.setThNums(feiliao_merNum);
				mwObject.setDiscriminationValue(pdobjectB.getDiscriminationValue());
				this.getMaterialWagesService().save(mwObject);
				
			}
			insV++;
			}	


					/**
					 * 工资单计算----------------------------------------------------
					 * --end
					 */

					/**
					 * 打回订单工资单计算-----------------------end----------------------
					 * ---------------------
					 */

				} else {
					// 不是打回生产
					 System.out.println("不是打回");

					/**
					 * 显示判断----------------------------------------------------
					 * ---start
					 */
					MaterialProduct mOP = this.getMaterialProductService()
							.getMaterialProduct(idObject[i]);
					double mpNum = mOP.getAlreadyProduct();
					int firstYN = mOP.getFirstYN();
					double materialProductNums = Double
							.parseDouble(materialProductNum[i]);
					double materialSjProNumss = Double
							.parseDouble(materialSjProNum[i]);
					/**
					 * first y n
					 */
					if (firstYN == 1) {
						if (materialSjProNumss >= materialProductNums) {
							mOP.setAlreadyProduct(materialSjProNumss);
							mOP.setFirstYN(2);
							mOP.setpLState(7);
							mOP.setRemainderNum(materialSjProNumss);
						 mOP.setNeedNum(Double.parseDouble(materialProductNum[i]) - materialSjProNumss);
							mOP.setProductScal(materialScal[i]);

						} else {
							mOP.setAlreadyProduct(materialSjProNumss);
							mOP.setRemainderNum(materialSjProNumss);
							mOP.setProductScal(materialScal[i]);
						mOP.setNeedNum(Double.parseDouble(materialProductNum[i]) - materialSjProNumss);
							mOP.setFirstYN(2);
						}
						this.getMaterialProductService().saveOrMaterialProduct(
								mOP);
					} else {
						double judgeV = materialProductNums - mpNum
								- materialSjProNumss;
						double Jud = mOP.getRemainderNum();
						if (judgeV > 0) {
							mOP.setAlreadyProduct(mpNum + materialSjProNumss);
							mOP.setProductScal(materialScal[i]);
							mOP.setRemainderNum(Jud + materialSjProNumss);

						} else {
							mOP.setAlreadyProduct(mpNum + materialSjProNumss);
							mOP.setRemainderNum(Jud + materialSjProNumss);
							mOP.setProductScal(materialScal[i]);
							mOP.setpLState(7);

						}
						this.getMaterialProductService().saveOrMaterialProduct(
								mOP);
					}

					MaterialTeam MtObject = this.getMaterialTeamService()
							.getMaterialTeam(productCodes[i], planOrOrderId[i]);
					if (MtObject != null) {
//						System.out
//								.println("剩余物料="
//										+ ((Double.parseDouble(MtObject
//												.getMaterialSyWuLiao()) + materialSjProNumss) + ""));
						MtObject.setMaterialSyWuLiao((Double
								.parseDouble(MtObject.getMaterialSyWuLiao()) + materialSjProNumss)
								+ "");
						this.getMaterialTeamService().saveOrMaterialTeam(
								MtObject);
					}

					/**
					 * 显示判断----------------------------------------------------
					 * ---end
					 */

//					wages = wages + materialSjProNumss;
//					funds = funds + Double.parseDouble(materialFeiLiao[i]);

					MaterialTeam materialTeam1 = new MaterialTeam();

					materialTeam1.setMaterialDate(materialTeam
							.getMaterialDate());
					materialTeam1.setMaterialCode(productCodes[i]);
					materialTeam1.setMaterialMachine(materialTeam
							.getMaterialMachine());
					materialTeam1.setMaterialClass(materialTeam
							.getMaterialClass());
					materialTeam1.setMaterialTotal(materialTeam
							.getMaterialTotal());
					materialTeam1.setMaterialZhuG(materialTeam
							.getMaterialZhuG());
					materialTeam1.setMaterialTechnician(materialTeam
							.getMaterialTechnician());
					materialTeam1.setMaterialProduction(materialTeam
							.getMaterialProduction());
					materialTeam1.setMaterialYanse(materialYanse[i]);
					materialTeam1.setMaterialNorm(materialNorm[i]);
					materialTeam1.setMaterialTanca(materialTanca[i]);
					materialTeam1.setMaterialPvc(materialPvc[i]);
					// System.out.println("比例=" + materialScal[i]);
					materialTeam1.setMaterialScal(materialScal[i]);
					materialTeam1.setMaterialDop(materialDop[i]);
					materialTeam1.setMaterialProductNum(materialProductNum[i]);
					materialTeam1.setMaterialSjProNum(materialSjProNum[i]);
					materialTeam1.setMaterialSyWuLiao(materialSjProNum[i]);
					materialTeam1.setMaterialCustomer(materialCustomer[i]);
					materialTeam1.setMaterialFeiLiao(materialFeiLiao[i]);
					materialTeam1.setMaterialStopState(materialStopState[i]);
					materialTeam1.setMaterialSuDu(materialSuDu[i]);
					materialTeam1.setMaterialRemark(materialRemark[i]);
					materialTeam1.setProductNums(productNums[i]);
					materialTeam1.setPlanCodeNum(planOrOrderId[i]);
					materialTeam1.setMaterialRushOrder(rushOrder[i]);
					materialTeam1.setMaterilaPackStyle(productPackstyle[i]);
					materialTeam1.setMaterialSupplier(supplierDate[i]);

					this.getMaterialTeamService().save(materialTeam1);

				}
				if(insV==0){
					for(int x=0;x<lengths;x++){
						wages = wages + Double.parseDouble(materialSjProNum[x]);;
						funds = funds + Double.parseDouble(materialFeiLiao[x]);
					}
					
					
				/**
				 * 人员比对-----------------start-------
				 */
				// 每个人本次制定分到的实际数量
				double shiji_merNum = 0.0;
				// 每个人本次制定分到的 废料数量
				double feiliao_merNum = 0.0;
				String personNames = materialTeam.getMaterialProduction();
				String lengthss[] = personNames.split(",");
				int personlength = lengthss.length;
				DecimalFormat df = new DecimalFormat("##.000");
				if (personlength > 0) {
					// 大于一个人，需要平分
					shiji_merNum = Double.parseDouble(df.format(wages
							/ personlength));
					feiliao_merNum = Double.parseDouble(df.format(funds
							/ personlength));
				} else {
					// 一个人独享
					shiji_merNum = wages;
					feiliao_merNum = funds;
				}
       
				/**
				 * 人员比对------------------end------
				 */
				/**
				 * 工资单计算------------------------------------------------------
				 * start wages funds
				 */
			
				
//					System.out.println("不是打回的    --------执行了几次");		
					ProvideRegime pdobjectA = this.getProvideRegimeService()
							.getProvideRegime("配料","实际产量",
									materialTeam.getMaterialClass(),
									materialTeam.getMaterialMachine());
					double shijichanliangNum = (double) pdobjectA.getSetNum();
					double jiangliDJ = pdobjectA.getRewardPrice();
					double chengfaDJ = pdobjectA.getPunishPrice();
					String uuDate=getCurrentDate();
					for (int z = 0; z < personlength; z++) {
						MaterialWages  mwObject=new MaterialWages();
						mwObject.setProStyles("实际产量");
						mwObject.setProvideNums(shijichanliangNum+"");
						mwObject.setProNames(lengthss[z]);
						mwObject.setPoundPrice(jiangliDJ);
						mwObject.setRwardPrice(chengfaDJ);
						mwObject.setRegDate(uuDate);
						mwObject.setThNums(shiji_merNum);
						mwObject.setDiscriminationValue(pdobjectA.getDiscriminationValue());
						this.getMaterialWagesService().save(mwObject);
						
					}
					ProvideRegime pdobjectB = this.getProvideRegimeService()
					.getProvideRegime("配料","废料",
							materialTeam.getMaterialClass(),
							materialTeam.getMaterialMachine());
			double feiliaoNum = (double) pdobjectB.getSetNum();
			double jiangliDJF = pdobjectB.getRewardPrice();
			double chengfaDJF = pdobjectB.getPunishPrice();
			
			for (int z = 0; z < personlength; z++) {
				MaterialWages  mwObject=new MaterialWages();
				mwObject.setProStyles("废料");
				mwObject.setProvideNums(feiliaoNum+"");
				mwObject.setProNames(lengthss[z]);
				mwObject.setPoundPrice(jiangliDJF);
				mwObject.setRwardPrice(chengfaDJF);
				mwObject.setRegDate(uuDate);
				mwObject.setThNums(feiliao_merNum);
				mwObject.setDiscriminationValue(pdobjectB.getDiscriminationValue());
				this.getMaterialWagesService().save(mwObject);
				
			}
			insV++;
				}
				
				
				


				/**
				 * 工资单计算------------------------------------------------------
				 * end
				 */

				/**
				 * 进入成型组混料单--------------------------start
				 */
				for (int h = 0; h < lengths; h++) {
					Molding mdObject = this.getMoldingService().getMolding(
							planOrOrderId[h], productCodes[h]);

				
					if (mdObject == null) {
						Molding mdd = new Molding();
						mdd.setMoldingCode(productCodes[h]);
						mdd.setMoldingName(materialCustomer[h]);
						mdd.setMoldingColor(materialYanse[h]);
						mdd.setMoldingNorm(materialNorm[h]);
						mdd.setMoldingTihuoDate(supplierDate[h]);
						mdd.setMoldingOrderPlan(planOrOrderId[h]);
						mdd.setMoldingRushOrder(rushOrder[h]);
						mdd.setMoldingNum(Integer.parseInt(productNums[h]));
						mdd.setOrderNum(Integer.parseInt(productNums[h]));
						mdd.setMoldingPackStyle(productPackstyle[h]);
						mdd.setMoldingBlance(materialScal[h]);
						this.getMoldingService().save(mdd);
					}
					// 已经存在这条记录
					else {
						// System.out.println("已有的数据=" +
						// mdObject.getMoldingNum());
						// System.out.println();
						// mdObject.setMoldingNum(mdObject.getMoldingNum()
						// + Integer.parseInt(materialSjProNum[h]));
						// this.getMoldingService().saveOrMolding(mdObject);

					}

					// 判断是不是打回生产的结束
				}
			}
			inintNum++;
		}
		/**
		 * 进入成型组混料单--------------------------END
		 */

	}

	public MaterialPrint getMaterialPrint() {
		return materialPrint;
	}

	public void setMaterialPrint(MaterialPrint materialPrint) {
		this.materialPrint = materialPrint;
	}

	public MaterialPrintService getMaterialPrintService() {
		return materialPrintService;
	}

	public void setMaterialPrintService(
			MaterialPrintService materialPrintService) {
		this.materialPrintService = materialPrintService;
	}

	public MaterialTeamService getMaterialTeamService() {
		return materialTeamService;
	}

	public void setMaterialTeamService(MaterialTeamService materialTeamService) {
		this.materialTeamService = materialTeamService;
	}

	public MaterialProduct getMaterialProduct() {
		return materialProduct;
	}

	public void setMaterialProduct(MaterialProduct materialProduct) {
		this.materialProduct = materialProduct;
	}

	public MaterialProductService getMaterialProductService() {
		return materialProductService;
	}

	public void setMaterialProductService(
			MaterialProductService materialProductService) {
		this.materialProductService = materialProductService;
	}

	public ProvideRegimeService getProvideRegimeService() {
		return provideRegimeService;
	}

	public void setProvideRegimeService(
			ProvideRegimeService provideRegimeService) {
		this.provideRegimeService = provideRegimeService;
	}

	public ProvideRegime getProvideRegime() {
		return provideRegime;
	}

	public void setProvideRegime(ProvideRegime provideRegime) {
		this.provideRegime = provideRegime;
	}

	public HrPerson getHrPerson() {
		return hrPerson;
	}

	public void setHrPerson(HrPerson hrPerson) {
		this.hrPerson = hrPerson;
	}

	public HrPersonService getHrPersonService() {
		return hrPersonService;
	}

	public void setHrPersonService(HrPersonService hrPersonService) {
		this.hrPersonService = hrPersonService;
	}

	public MoldingService getMoldingService() {
		return moldingService;
	}

	public void setMoldingService(MoldingService moldingService) {
		this.moldingService = moldingService;
	}

	@Override
	public MaterialTeam getMaterialTeam(String materialCode, String planCodeNum) {
		return this.getDao().getMaterialTeam(materialCode, planCodeNum);
	}

	/**
	 * 成型單打回的數據操作
	 */
	
	@Override
	public void returnTrackMaterialTeam(String productCode, String orderplan,
			String needNum) {
		MaterialProduct MpObject = this.getMaterialProductService()
				.getMaterialProductOrPro(orderplan, productCode);
		MaterialProduct MpBackObject = new MaterialProduct();

		MpBackObject.setProductCode(productCode);
		MpBackObject.setProductName(MpObject.getProductName());
		MpBackObject.setProductColor(MpObject.getProductColor());
		MpBackObject.setProductNorm(MpObject.getProductNorm());
		MpBackObject.setDeliveryDate(MpObject.getDeliveryDate());
		MpBackObject.setRushOrder(MpObject.getRushOrder());
		MpBackObject.setRemainderNum(MpObject.getRemainderNum());
//		MpBackObject.setNeedNum(Double.parseDouble(needNum)
//				+ MpObject.getNeedNum());
		MpBackObject.setNeedNum(Double.parseDouble(needNum));
		MpBackObject.setBackMakeState(4);
		MpBackObject.setpLState(1);
		MpBackObject.setPlanOrOrderId(orderplan);
		MpBackObject.setFirstYN(1);
		MpBackObject.setProductPackstyle(MpObject.getProductPackstyle());
		MpBackObject.setProductNum(MpObject.getProductNum());
		MpBackObject.setAlreadyProduct(0.000);
		MpBackObject.setProductScal(MpObject.getProductScal());
		MpBackObject.setNumConfirmState(1);
		this.getMaterialProductService().save(MpBackObject);

	}

	@Override
	public void backTrackMaterialTeam(String productCode, String orderplan,
			Double nums, Double arealyNums) {
		// System.out.println("nums=" + nums);
		/**
		 * 修改查询配料数据
		 */
		MaterialTeam mtObject = this.getMaterialTeamService().getMaterialTeam(
				productCode, orderplan);
		mtObject.setMaterialSyWuLiao((Double.parseDouble(mtObject
				.getMaterialSyWuLiao()) - arealyNums + nums)
				+ "");
		this.getMaterialTeamService().saveOrMaterialTeam(mtObject);
		/**
		 * 修改制定配料数据
		 */

		MaterialProduct mpObject = this.getMaterialProductService()
				.getMaterialProductOrProAndFirst(productCode, orderplan);
//		System.out.println("mpObject.getRemainderNum()=" + mpObject);
		mpObject.setRemainderNum(mpObject.getRemainderNum() - arealyNums + nums);
		this.getMaterialProductService().saveOrMaterialProduct(mpObject);

	}

	@Override
	public void saveOrMaterialTeam(MaterialTeam materialTeam) {
		this.getDao().saveOrMaterialTeam(materialTeam);
	}

	@Override
	public void backTrackMaterialTeamHunZero(String productCode,
			String orderplan, Double nums, Double arealyNums) {
		/**
		 * 修改查询配料数据
		 */
		MaterialTeam mtObject = this.getMaterialTeamService().getMaterialTeam(
				productCode, orderplan);
		mtObject.setMaterialSyWuLiao((Double.parseDouble(mtObject
				.getMaterialSyWuLiao()) - arealyNums) + "");
		this.getMaterialTeamService().saveOrMaterialTeam(mtObject);
		/**
		 * 修改制定配料数据
		 */

		MaterialProduct mpObject = this.getMaterialProductService()
				.getMaterialProductOrProAndFirst(productCode, orderplan);
		// System.out.println("mpObject.getRemainderNum()=" + mpObject);
		mpObject.setRemainderNum(mpObject.getRemainderNum() - arealyNums);
		this.getMaterialProductService().saveOrMaterialProduct(mpObject);

	}

	/**
	 * 创建预览
	 */
	@Override
	public void saveMaterialTeamPrint(MaterialTeam materialTeam,
			String[] materialYanse, String[] materialNorm,
			String[] materialTanca, String[] materialPvc,
			String[] materialScal, String[] materialDop,
			String[] materialProductNum, String[] materialSjProNum,
			String[] materialSyWuLiao, String[] materialCustomer,
			String[] materialFeiLiao, String[] materialStopState,
			String[] materialSuDu, String[] materialRemark,
			String[] productNums, Integer[] idObject, String[] planOrOrderId,
			Date[] supplierDate, String[] rushOrder, String[] productCodes,
			String[] productPackstyle, Integer[] backProductSate) {

		int lengths = backProductSate.length;
		/**
		 * 打印编号
		 */
		String CodeNumbers = "04070020101202P1";
		SerialNumberss snObject = this.getSerialNumberssService()
				.getSerialNumberss("配料组打印");
		if (snObject == null) {
			SerialNumberss snmm = new SerialNumberss();
			snmm.setStyCategory("配料组打印");
			snmm.setStyNumberCode(CodeNumbers);
			this.getSerialNumberssService().save(snmm);
		} else {
			String codeF = snObject.getStyNumberCode();
			String DF[] = codeF.split("P");
			int lastCode = Integer.parseInt(DF[1]) + 1;
			CodeNumbers = DF[0] + "P" + lastCode;
			snObject.setStyNumberCode(CodeNumbers);
			this.getSerialNumberssService().setNumCode(snObject);
		}

		repaceNull(materialTeam);
		MaterialPrint mpObject = new MaterialPrint();
		mpObject.setMaterialMachine(materialTeam.getMaterialMachine());
		mpObject.setMaterialClass(materialTeam.getMaterialClass());
		mpObject.setMaterialTotal(materialTeam.getMaterialTotal());
		mpObject.setMaterialCharge(materialTeam.getMaterialZhuG());
		mpObject.setMaterialTechnician(materialTeam.getMaterialTechnician());
		mpObject.setMaterialPrintCode(CodeNumbers);
		for (int i = 0; i < lengths; i++) {
			MaterialPrintDetail mpd = new MaterialPrintDetail();
			mpd.setMaterialColor(materialYanse[i]);
			mpd.setMaterialNorm(materialNorm[i]);
			mpd.setMaterialCa(materialTanca[i]);
			mpd.setMaterialPvc(materialPvc[i]);
			mpd.setMaterialScal(materialScal[i]);
			mpd.setMaterialDop(materialDop[i]);
			mpd.setMaterialProductNum(materialProductNum[i]);
			mpd.setMaterialSjProNum(materialSjProNum[i]);
			mpd.setMaterialSyWuLiao(materialSyWuLiao[i]);
			mpd.setMaterialCustomer(materialCustomer[i]);
			mpd.setMaterialFeiLiao(materialFeiLiao[i]);
			mpd.setMaterialStopState(materialStopState[i]);
			mpd.setMaterialSuDu(materialSuDu[i]);
			mpd.setMaterialRemark(materialRemark[i]);
			mpObject.addDetail(mpd);

		}
		this.getMaterialPrintService().save(mpObject);

	}

	public SerialNumberssService getSerialNumberssService() {
		return serialNumberssService;
	}

	public void setSerialNumberssService(
			SerialNumberssService serialNumberssService) {
		this.serialNumberssService = serialNumberssService;
	}

	void repaceNull(MaterialTeam materialTeam) {

		if (materialTeam.getMaterialClass() == null
				|| materialTeam.getMaterialClass() == "") {
			materialTeam.setMaterialClass("");
		}
		if (materialTeam.getMaterialMachine() == null
				|| materialTeam.getMaterialMachine() == "") {
			materialTeam.setMaterialMachine("");
		}
		if (materialTeam.getMaterialTotal() == null) {
			materialTeam.setMaterialTotal(0.0);
		}
		if (materialTeam.getMaterialZhuG() == null) {
			materialTeam.setMaterialZhuG("");
		}
		if (materialTeam.getMaterialTechnician() == null) {
			materialTeam.setMaterialTechnician("");
		}
	}

	@Override
	public List<MaterialTeam> getMaterialTeamOrderpLan(String orderplan) {

		return this.getDao().getMaterialTeamOrderpLan(orderplan);
	}

	public static String getCurrentDate() {
		Calendar cal = Calendar.getInstance();
		int year = cal.get(Calendar.YEAR);
		int month = cal.get(Calendar.MONTH) + 1;
        int days=cal.get(Calendar.DATE);   
		return days+"/"+month + "/" + year;
	}

	public EarningSalService getEarningSalService() {
		return earningSalService;
	}

	public void setEarningSalService(EarningSalService earningSalService) {
		this.earningSalService = earningSalService;
	}

	public MaterialWagesService getMaterialWagesService() {
		return materialWagesService;
	}

	public void setMaterialWagesService(
			MaterialWagesService materialWagesService) {
		this.materialWagesService = materialWagesService;
	}

	public MoldingWagesService getMoldingWagesService() {
		return moldingWagesService;
	}

	public void setMoldingWagesService(MoldingWagesService moldingWagesService) {
		this.moldingWagesService = moldingWagesService;
	}

	public PrintWagesService getPrintWagesService() {
		return printWagesService;
	}

	public void setPrintWagesService(PrintWagesService printWagesService) {
		this.printWagesService = printWagesService;
	}
	
	

}
